{% extends "admin/layout.html" %}

{% block head %}
    {{ super() }}
    <meta name="viewport" content="width=device-width, initial-scale=1">
{% endblock %}

{% block title %}控制台 - {{ system_config.site_name|default('后台管理系统') }}{% endblock %}

{% block page_title %}控制台{% endblock %}

{% block breadcrumb %}
<li class="breadcrumb-item"><a href="{{ url_for('admin.dashboard') }}">首页</a></li>
<li class="breadcrumb-item active">控制台</li>
{% endblock %}

{% block content %}
<div class="row">
    <!-- 统计卡片 -->
    <div class="col-lg-3 col-6">
        <div class="card">
            <div class="card-body">
                <div class="d-flex justify-content-between">
                    <div>
                        <h5 class="card-title">用户数量</h5>
                        <h2>{{ user_count }}</h2>
                    </div>
                    <div class="align-self-center">
                        <i class="fas fa-users fa-2x text-primary"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-lg-3 col-6">
        <div class="card">
            <div class="card-body">
                <div class="d-flex justify-content-between">
                    <div>
                        <h5 class="card-title">群组数量</h5>
                        <h2>{{wx_group_count}}</h2>
                    </div>
                    <div class="align-self-center">
                        <i class="fas fa-user-tag fa-2x text-success"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-lg-3 col-6">
        <div class="card">
            <div class="card-body">
                <div class="d-flex justify-content-between">
                    <div>
                        <h5 class="card-title">部门数量</h5>
                        <h2>{{department_count}}</h2>
                    </div>
                    <div class="align-self-center">
                        <i class="fas fa-key fa-2x text-info"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-lg-3 col-6">
        <div class="card">
            <div class="card-body">
                <div class="d-flex justify-content-between">
                    <div>
                        <h5 class="card-title">员工数量</h5>
                        <h2>{{ member_count }}</h2>
                    </div>
                    <div class="align-self-center">
                        <i class="fas fa-address-card fa-2x text-warning"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row mt-4">
    <!-- 最近活动 -->
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">最近活动</h3>
            </div>
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-hover" aria-label="最近活动记录" aria-describedby="recentActivities">
                        <thead>
                            <tr>
                                <th scope="col">管理员</th>
                                <th scope="col">操作</th>
                                <th scope="col">资源</th>
                                <th scope="col">时间</th>
                                <th scope="col">IP地址</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for log in recent_logs %}
                            <tr>
                                <td>{{ log.admin.username }}</td>
                                <td>{{ log.action }}</td>
                                <td>{{ log.resource }}</td>
                                <td>{{ log.timestamp.strftime('%Y-%m-%d %H:%M') }}</td>
                                <td>{{ log.ip_address }}</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <!-- 系统信息 -->
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">最近备份</h3>
            </div>
            <div class="card-body p-0">
                <ul class="list-group list-group-flush">
                    {% for backup in recent_backups %}
                    <li class="list-group-item">
                        <div class="d-flex justify-content-between">
                            <div>
                                <h6 class="mb-1">{{ backup.backup_type }}</h6>
                                <small class="text-muted">{{ backup.backup_time.strftime('%Y-%m-%d %H:%M') }}</small>
                            </div>
                            <span class="badge bg-{{ 'success' if backup.status == '成功' else 'danger' }}" aria-label="备份状态: {{ backup.status }}">{{ backup.status }}</span>
                        </div>
                    </li>
                    {% endfor %}
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %}